namespace PickGold.Charting.Design
{
    using System;
    using System.ComponentModel;
    using System.Drawing.Design;
    using System.Windows.Forms.Design;

    internal class AnnotationAxisUITypeEditor : UITypeEditor
    {
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (((context != null) && (context.Instance != null)) && (provider != null))
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService) provider.GetService(typeof(IWindowsFormsEditorService));
                if ((edSvc == null) || !(context.Instance is Annotation))
                {
                    return value;
                }
                bool showXAxes = true;
                if ((context.PropertyDescriptor != null) && (context.PropertyDescriptor.Name == "AxisY"))
                {
                    showXAxes = false;
                }
                AnnotationAxisNameTreeView control = new AnnotationAxisNameTreeView(edSvc, (Annotation) context.Instance, value as Axis, showXAxes);
                edSvc.DropDownControl(control);
                value = control.GetNewValue();
                control.Dispose();
            }
            return value;
        }

        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            if ((context != null) && (context.Instance != null))
            {
                return UITypeEditorEditStyle.DropDown;
            }
            return base.GetEditStyle(context);
        }
    }
}

